package com.gitee.wsl.mathematics.matrix.mat

import com.gitee.wsl.io.dataproxy.DataProxy
import com.gitee.wsl.collections.map.OpenIntToDoubleHashMap

class SparseHashMapMatrix(
                   rowCount: Int,
                   colCount: Int = rowCount,
                   proxy: DataProxy<Double> = OpenIntToDoubleHashMap(0.0).asProxy(rowCount*colCount)
): AbstractMatrix<SparseHashMapMatrix>(rowCount, colCount, proxy) {
    override val self: SparseHashMapMatrix
        get() = this
}


fun OpenIntToDoubleHashMap.asProxy(size: Int) = OpenIntToDoubleHashMapProxy(size,this)

class OpenIntToDoubleHashMapProxy(override val size: Int,val base: OpenIntToDoubleHashMap):DataProxy<Double>{

    override fun fill(value: Double, fromIndex: Int, toIndex: Int) {
        (fromIndex..toIndex).forEach { set(it,value) }
    }

    override fun get(index: Int): Double {
        return base[index]
    }

    override fun values(): List<Double> = (0..size).map { get(it) }

    override fun set(index: Int, value: Double) {
        base[index] = value
    }

}
